<%@ page language="java" %>

<%@ page import="com.scalar.chiptrack.commons.SessionKeys,
                 com.scalar.chiptrack.utils.ConfigManager,
				 com.scalar.chiptrack.commons.Constants,
				 com.scalar.chiptrack.users.Functionality,
				 com.scalar.chiptrack.users.User"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<chiptrack:checkLogon sourcePage="/shippingRequest.do" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet"></HEAD>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>

<SCRIPT language="JavaScript">

/*To enter the Qty available while selecting the checkbox,if deselecting the checkbox
transfer Ship Qty field is disabled */
function setSelectAllIds( Object, idx)
{
    if( document.shippingRequestForm['shippingRequest.lotList['+idx+'].checked'].checked == true )
    {
        document.shippingRequestForm['shippingRequest.lotList['+idx+'].pulledQty'].disabled = false;
        document.shippingRequestForm['shippingRequest.lotList['+idx+'].pulledQty'].value = document.shippingRequestForm['shippingRequest.lotList['+idx+'].availableQty'].value;
    }
    else
    {
        document.shippingRequestForm['shippingRequest.lotList['+idx+'].pulledQty'].value = 0;
        document.shippingRequestForm['shippingRequest.lotList['+idx+'].pulledQty'].disabled = true;
    }

}

/*code for restricting the user to enter numbers and decmals*/
function numcheck()
{
	if(((event.keyCode<48)||(event.keyCode>57)))
	{
		if(event.keyCode==46)
		{
			event.keyCode=0;
		}
		else
		{
			event.keyCode=0;
		}
	}
}

var dateElement = "";
function openCalendar( dateValue )
{
    dateElement = dateValue;
    newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
    newWindow.focus();
}
function assignDate( passedValue )
{
    dateElement.value=passedValue;
    window.focus();
}
var lotNumberListSize = 0;
function createTransfer()
{
    var errors = "";
    var shipDate = document.shippingRequestForm['shippingRequest.shipReqDate'];
    if( chkDate(shipDate.value.trim(),"Request Date ","Y") == false)
    {
        errors = errMsg;
        shipDate.select();
        shipDate.focus();
    }
    if( document.shippingRequestForm['shippingRequest.shipperId'].value == -1 )
    {
        errors = errors + "<li>Select the Shipper";
    }

    var isLotSelected = false;
    for ( i=0; i < lotNumberListSize; i++ )
    {
       var lotCheckCtrl = document.shippingRequestForm['shippingRequest.lotList['+i+'].checked'];
       if ( lotCheckCtrl.checked )
       {
           isLotSelected = true;
           break;
       }
    }
    for ( i=0; i < lotNumberListSize; i++ )
    {
       var lotCheckCtrl = document.shippingRequestForm['shippingRequest.lotList['+i+'].checked'];
       var pulledQty = document.shippingRequestForm['shippingRequest.lotList['+i+'].pulledQty'].value;
       var lotNumber = document.shippingRequestForm['shippingRequest.lotList['+i+'].lotNumber'].value;
       var availQty = document.shippingRequestForm['shippingRequest.lotList['+i+'].availableQty'].value;

       if( lotCheckCtrl.checked && pulledQty == 0 )
       {
            errors = errors + "<li>Please Enter Transfer Qty for Lot Number:"+ lotNumber +"</li>"
       }
       if( parseInt(pulledQty) >parseInt(availQty ) )
       {
            errors = errors + "<li>Transfer Qty Cannot be Greater than Available Qty for Lot Number:"+ lotNumber +"</li>"
       }
    }
    if ( isLotSelected == false )
    {
        errors = errors + "<li>Please select atleast one lot to ship</li>"
    }
    if( errors != "" )
    {
        var pa = document.getElementById("errors");
        pa.innerHTML = errors;
        return false;
    }
    enableFields();
    document.shippingRequestForm.action = '<%=chipTracContext%>/shippingRequest.do?action=save';
    return true;
}
    function reset()
    {
        document.shippingRequestForm.reset();
        for ( i=0; i < lotNumberListSize; i++ )
        {
            var lotCheckCtrl  = document.shippingRequestForm['shippingRequest.lotList['+i+'].checked'];
            var pulledQtyCtrl = document.shippingRequestForm['shippingRequest.lotList['+i+'].pulledQty'];
            if ( lotCheckCtrl.checked )
            {
                pulledQtyCtrl.disabled = false;
            }
            else
            {
                pulledQtyCtrl.value = 0;
                pulledQtyCtrl.disabled = true;
            }
        }
        calculateRunningTotal();
    }
    function calculateRunningTotal()
    {
        var form = document.shippingRequestForm;
        var runningTotalCtrl = form['runningTotal'];
        var totalPulledQty = 0;
        for ( i=0; i < lotNumberListSize; i++ )
        {
            var pulledQtyCtrl = document.shippingRequestForm['shippingRequest.lotList['+i+'].pulledQty'];
            totalPulledQty = totalPulledQty + Number(pulledQtyCtrl.value);
        }
        runningTotalCtrl.value = totalPulledQty;
    }
    function enableFields()
    {
        var form = document.shippingRequestForm;
        for ( i=0; i < lotNumberListSize; i++ )
        {
            var lotCheckCtrl  = document.shippingRequestForm['shippingRequest.lotList['+i+'].checked'];
            var pulledQtyCtrl = document.shippingRequestForm['shippingRequest.lotList['+i+'].pulledQty'];

            lotCheckCtrl.disabled = false;
            pulledQtyCtrl.disabled = false;
        }
    }
</SCRIPT>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0" onload="calculateRunningTotal()">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
	<TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

	<!-- Side Navigation start -->
	<%@ include file="/jsp/operations/dataentryMenu.jsp" %></TD>
	<!-- end of the side navigations -->

	<TD bgcolor="#ffffff">
	<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
	<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
	<TD valign="top" width="100%">

	<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
	<BR>

	<html:form action="/shippingRequest.do" name="shippingRequestForm" method="POST" scope="session" type="com.scalar.chiptrack.operations.shippingRequest.forms.ShippingRequestForm">
       	<nested:nest property="shippingRequest" >
        <TABLE width="80%" align="center" cellpadding="2" cellspacing="2" border="0">
			<TR><TD colspan="4" class="NArialW" align="center">Ship Request</TD></TR>

			<TR><TD colspan='4' align="left" class='NArialL'>&nbsp;<FONT id="errors" color='FF0000'></font></TD></TR>
			<TR><TD colspan='4' class="NArialL"><chiptrack:errors styleClass="NArialL"/></TD></TR>
			<TR><TD colspan='4' class="NArialL"><chiptrack:info styleClass="NArialL"/></TD></TR>
			<TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <tr>
			<td class="NArialL" width="20%">
				Ship Request #:<font color=red>*</font>
			</td>
			<td class="NArialL" width="15%">
                <nested:text  property="shipReqNumber" styleClass="txfield" disabled="true"/>
			</td>
			<td class="NArialL" width="20%">
				Ship Req Date:<font color=red>*</font>
			</td>
			<td class="NArialL" width="25%">
			    <nested:text  property="shipReqDate" size="11" styleClass="txfield" />
                <a href="javascript:openCalendar( document.shippingRequestForm['shippingRequest.shipReqDate'] )">
                    <img onMouseOver="window.status='Click  to select date';return true" onMouseout="window.status='';return 	true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20>
                </a>
			</td>
            </tr>
             <tr>
                <td class="NArialL" width="20%">From Location:
				</td>
                <td width="15%" class="NArialL" nowrap>
                    <nested:text  property="fromVendorName" size="20" maxlength="50"  styleClass="txfield" disabled="true"/>
                </td>
                <td class="NArialL"colspan="2" width="20%">&nbsp;</td>
            </tr>
            <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <tr>
				<td class="NArialL">
					Address1:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.address1" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					Address2:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.address2" size="20" styleClass="txfield" disabled="true"/>
				</td>
			</tr>
			<tr>
				<td class="NArialL">
					Address3:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.address3" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					Address4:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.address4" size="20" styleClass="txfield" disabled="true"/>
				</td>
			</tr>
			<tr>
				<td class="NArialL">
					City:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.city" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					State:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.state" size="20" styleClass="txfield" disabled="true"/>
				</td>
			</tr>
			<tr>
				<td class="NArialL">
					Country:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.country" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					Zip:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.zipCode" size="20" styleClass="txfield" disabled="true"/>
				</td>
			</tr>
            <tr>
                <td class="NArialL">
					Phone:
				</td>
                <td class="NArialL">
					<nested:text property="fromVendorAddress.phoneNumber" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					Fax:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.faxNumber" size="20" styleClass="txfield" disabled="true"/>
				</td>
            </tr>
            <tr>
                <td class="NArialL">
					Contact Person:
				</td>
                    <td class="NArialL">
					<nested:text property="fromVendorAddress.contactPerson" size="20" styleClass="txfield" disabled="true"/>
				</td>

				<td class="NArialL">
					Email:
				</td>
				<td class="NArialL">
					<nested:text property="fromVendorAddress.email" size="20" styleClass="txfield" disabled="true"/>
				</td>
            </tr>
             <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
             <tr>
                <td class="NArialL" width="20%">Ship To Location:
				</td>
                <td width="15%" class="NArialL" nowrap>
                    <nested:text  property="toVendorName" size="20" maxlength="50"  styleClass="txfield" disabled="true"/>
                </td>
                <td class="NArialL"colspan="2" width="20%">&nbsp;</td>
             </tr>
             <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <tr>
				<td class="NArialL">
					Address1:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.address1" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					Address2:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.address2" size="20" styleClass="txfield" disabled="true"/>
				</td>
			</tr>
			<tr>
				<td class="NArialL">
					Address3:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.address3" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					Address4:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.address4" size="20" styleClass="txfield" disabled="true"/>
				</td>
			</tr>
			<tr>
				<td class="NArialL">
					City:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.city" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					State:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.state" size="20" styleClass="txfield" disabled="true"/>
				</td>
			</tr>
			<tr>
				<td class="NArialL">
					Country:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.country" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					Zip:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.zipCode" size="20" styleClass="txfield" disabled="true"/>
				</td>
			</tr>
            <tr>
                <td class="NArialL">
					Phone:
				</td>
                <td class="NArialL">
					<nested:text property="toVendorAddress.phoneNumber" size="20" styleClass="txfield" disabled="true"/>
				</td>
				<td class="NArialL">
					Fax:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.faxNumber" size="20" styleClass="txfield" disabled="true"/>
				</td>
            </tr>
            <tr>
                <td class="NArialL">
					Contact Person:
				</td>
                    <td class="NArialL">
					<nested:text property="toVendorAddress.contactPerson" size="20" styleClass="txfield" disabled="true"/>
				</td>

				<td class="NArialL">
					Email:
				</td>
				<td class="NArialL">
					<nested:text property="toVendorAddress.email" size="20" styleClass="txfield" disabled="true"/>
				</td>
            </tr>
            <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <tr>
                <td class="NArialL" width="15%">Shipper:<font color=red>*</font>
                </td>
                <td width="15%" class="NArialL" nowrap>
                    <nested:select  property="shipperId"  styleClass="txfield">
                        <html:option value="-1">--Select--</html:option>
                        <nested:optionsCollection property="shippersList" value="value" label="label"/>
                    </nested:select>
                </td>
                <td class="NArialL"colspan="2" width="20%">&nbsp;</td>
            </tr>
            <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <tr>
                <td class="NArialL" width="35%">Please send Ship Alerts:
                </td>
                <td class="NArialL"colspan="3" width="20%"><nested:textarea property="shipAlerts" cols="38" rows="7" styleClass="txfield" disabled="true"/></td>
            </tr>
            <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <tr>
                <td class="NArialL" colspan="2"  width="45%"><b>Please Ship the following Product</b>
                </td>
                <td class="NArialL" colspan="2" width="20%">&nbsp;</td>
            </tr>
            <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
             <tr>
                <td class="NArialL" width="15%"> Product :
                </td>
                <td width="15%" class="NArialL" nowrap>
                    <nested:text property="partNumber" size="20" maxlength="50"  styleClass="txfield" disabled="true"/>
                </td>
                <td class="NArialL"colspan="2" width="20%">&nbsp;</td>
            </tr>

           <TR>
                <TD colspan='4'>
                    <table width="50%" align="left" cellpadding="2" cellspacing="2" border="0">
                        <tr>
                             <td width="3%" class="NArialL" bgcolor="#993333" nowrap align="center" >
                                <font color="#FFFFFF" >Select</font>
                             </td>
                            <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                                <font color="#FFFFFF">Lot Number</font>
                            </td>
                            <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                                <font color="#FFFFFF">Qty Available</font>
                            </td>
                            <td width="10%" class="NArialL" bgcolor="#993333" nowrap align="center">
                                <font color="#FFFFFF">Transfer Qty</font>
                            </td>

                        </tr>
                        <nested:iterate property="lotList" type="com.scalar.chiptrack.operations.shippingRequest.ShippingRequestLot" id="shippingRequestLot" indexId="iteratorIdx" >
                          <tr  <%  if ( iteratorIdx.intValue()%2==0 ) { %>
                              bgcolor='#DEE1E2'
                            <% } else {%>
                            bgcolor='#FFFFEE'
                            <%}
                                String jsFuntion = "setSelectAllIds(this,"+iteratorIdx+");calculateRunningTotal();";
                            %> >
                                <td width ="3%" align="center" class='NArialL' >
                                    <nested:equal property = "disabled" value="true">
                                        <nested:checkbox property="checked" disabled="true"/>
                                    </nested:equal>
                                    <nested:notEqual property = "disabled" value="true">
                                        <nested:checkbox property="checked" onclick="<%=jsFuntion%>"/>
                                    </nested:notEqual>
                                </td>
                                <td width="10%" class="NArialL" nowrap>
                                    <nested:write property="lotNumber" />
                                    <nested:hidden property="lotNumber" />
                                </td>
                                <td width="10%" align='right' class="NArialL">
                                    <nested:write property="availableQty" />
                                </td>
                                <td width="10%" align='right' class="NArialL">
                                    <nested:equal property="checked" value="true">
                                        <nested:equal property = "disabled" value="true">
                                            <nested:text property ="pulledQty" disabled="true" styleClass="valuetxfield" maxlength="7" />
                                        </nested:equal>
                                        <nested:notEqual property = "disabled" value="true">
                                            <nested:text property ="pulledQty" onkeypress="javascript:numcheck()" styleClass="valuetxfield" maxlength="7" onkeyup="calculateRunningTotal()"/>
                                        </nested:notEqual>
                                    </nested:equal>
                                    <nested:notEqual property="checked" value="true">
                                        <nested:text property ="pulledQty" onkeypress="javascript:numcheck()" styleClass="valuetxfield" disabled="true" maxlength="7" onkeyup="calculateRunningTotal()"/>
                                    </nested:notEqual>
                                </td>
                                <nested:hidden property="availableQty"/>
                                <nested:hidden property="lotId" />
                          </tr>
                        </nested:iterate>
                        <TR>
                            <TD>&nbsp;</TD>
                            <TD colspan="2" align="right" class="NArialL">Running Total:</TD>
                            <TD><input type="text" name="runningTotal" class="valuetxfield" disabled="true"></TD>
                        </TR>
                        <nested:size property="lotList" id="lotListSize"/>
                        <SCRIPT>
                            lotNumberListSize = <%=lotListSize%>;
                        </SCRIPT>

                    </table>
                </TD>
           </TR>

            <tr>
            <td class="NArialL" width="15%">
                Special Instructions:
			</td>
            <td class="NArialL" width="25%" >
			    <nested:textarea  property="specialInstr" styleClass="txfield" cols="30" rows="5"/>
			</td>
            <td class="NArialL"colspan="2" width="20%">&nbsp;</td>
			</tr>
             <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
             <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <tr>
				<td colspan="5" align="center">
                <input type=image border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" onClick ="javascript:return createTransfer();" width="53" height="17" onmouseover="window.status='Click to Search for Class Store Lots';return true" onmouseout="window.status='';return true" title="Click here to Search for Class Store lots"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="javascript:reset()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
				</td>
			</tr>
            <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
		</TABLE>
    </nested:nest>
	</html:form>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</BODY>
</HTML>